<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 韩金龙
  Date: 2021/11/5
  Time: 9:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/fileupload.js"></script>
    <link rel="stylesheet" href="css/css.css">
    <link rel="stylesheet" href="css/img.css">
</head>
<body>
        <form action="list.do" method="post">
            <input type="hidden" name="pageNum">
            名称:<input type="text" name="cname" value="${param.cname}">
            日期:<input type="text" name="ontimeMin" value="${param.ontimeMin}">-<input type="text" name="ontimeMax" value="${param.ontimeMax}">
            品牌:<select name="tid"><option value="">请选择</option> </select>
            :<input type="submit" value="搜索">
        </form>
        <table>
            <tr>
                <td>
                    <input type="checkbox">
                </td>
                <td>编号</td>
                <td>名称</td>
                <td>图片</td>
                <td>日期</td>
                <td>价格</td>
                <td>颜色</td>
                <td>产地</td>
                <td>品牌</td>
                <td>操作</td>
            </tr>
            <c:forEach items="${pageInfo.list}" var="li">
                <tr>
                    <td>
                        <input type="checkbox" class="xz" value="${li.cid}">
                    </td>
                    <td>${li.cid}</td>
                    <td>${li.cname}</td>
                    <td>
                        <img src="${li.pic}" alt="无法显示" width="50px">
                    </td>
                    <td>${li.ontime}</td>
                    <td>${li.price}万元</td>
                    <td>${li.conames}</td>
                    <td>${li.shengName}-${li.shiName}-${li.xianName}</td>
                    <td>${li.tname}</td>
                    <td>
                        <button onclick="upd(${li.cid})">修改</button>
                        <button onclick="del(${li.cid})">删除</button>
                    </td>
                </tr>
            </c:forEach>
            <tr>
                <td colspan="20">
                    <button onclick="fye(1)">首页</button>
                    <button onclick="fye(${pageInfo.isFirstPage?1:pageInfo.prePage})">上页</button>
                    <button onclick="fye(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">下页</button>
                    <button onclick="fye(${pageInfo.pages})">尾页</button>
                    第${pageInfo.pageNum}/${pageInfo.pages}页
                </td>
            </tr>
            <tr>
                <td colspan="20">
                    <button onclick="addTo()">添加</button>
                    <button onclick="qx()">全选</button>
                    <button onclick="qbx()">全不选</button>
                    <button onclick="dels()">批删</button>
                </td>
            </tr>
        </table>
</body>
<script>
    $(function () {
        $.ajax({
            url:"typeList.do",
            type:"post",
            dataType:"json",
            success:function (obj) {
                console.log(obj)
                for (let i in obj) {
                    $("[name='tid']").append("<option value="+obj[i].tid+">"+obj[i].tname+"</option>")
                }
                $("[name='tid']").val(${param.tid})
            }
        })
    })//动态下拉
    function addTo() {
        location="addTo.do"
    }
    function fye(pageNum) {
        $("[name='pageNum']").val(pageNum)
        $("form").submit()
    }//分页
    function qx() {
        $(".xz").prop("checked",true)
    }//全选
    function qbx() {
        $(".xz").prop("checked",false)
    }//全不选
    function dels() {
        var cid=0
        $(".xz:checked").each(function () {
            var id=$(this).val()
            cid+=","+id
        })
        $.ajax({
            url:"del.do",
            type:"post",
            dataType:"json",
            data:{"cid":cid},
            success:function (obj) {
                if (obj>0){
                    alert("删除成功!")
                    location="list.do"
                }
            }
        })
    }//批删
    function del(cid) {
        $.ajax({
            url:"del.do",
            type:"post",
            dataType:"json",
            data:{"cid":cid},
            success:function (obj) {
                if (obj>0){
                    alert("删除成功!")
                    location="list.do"
                }
            }
        })
    }
    function upd(cid) {
        location="upd.do?cid="+cid
    }
</script>
</html>
